package com.bwton.msx.ccb.ui.setting;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Switch;

import com.bwton.msx.ccb.R;
import com.bwton.msx.ccb.utils.PreferenceUtil;
import com.sensetime.ssidmobile.sdk.liveness.model.config.DefakeConfig;

/**
 * @author chenliang1
 */
public class SettingDefakeFragment extends Fragment {

    private Switch mDefakeSwitch;
    private EditText mEditDefakeTimeoutMillis;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_defake_setting, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mDefakeSwitch = view.findViewById(R.id.switch_defake);

        DefakeConfig defakeConfig = PreferenceUtil.getDefakeConfig();
        mDefakeSwitch.setChecked(defakeConfig.isDefake);

        mEditDefakeTimeoutMillis = view.findViewById(R.id.edit_defake_time_out_millis);
        mEditDefakeTimeoutMillis.setText(String.valueOf(defakeConfig.timeOutMillis));

    }


    @Override
    public void onPause() {
        super.onPause();
        DefakeConfig defakeConfig = new DefakeConfig.Builder()
                .setDefake(mDefakeSwitch.isChecked())
                .setTimeOutMillis(Long.valueOf(mEditDefakeTimeoutMillis.getText().toString()))
                .build();
        PreferenceUtil.setDefakeConfig(defakeConfig);
    }
}